package com.kehongborui.net.socket.tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * TCP socket 客户端
 */
public class ClientDemo {
    private static final String IP = "10.3.16.211";  // 服务端的IP
    private static final int PORT = 9999; // 服务端的端口

    public static void main(String[] args) throws IOException {
        Socket client = new Socket(IP, PORT);  // 创建客户端 socket 对象
        InputStream inputStream = client.getInputStream();  // 获取服务端的数据流

        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); // 转换成字符流

        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        // 关闭流
        reader.close();
        client.close();
    }
}
